package vn.bk.hotel.dialog;

import vn.bk.hotel.R;
import vn.bk.hotel.global.Language;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class DialogChooseLanguage {
    private AlertDialog.Builder dialog;

    public DialogChooseLanguage(final Activity context) {
	View view = View
		.inflate(context, R.layout.dialog_choose_language, null);
	dialog = new AlertDialog.Builder(context);
	final RadioGroup group = (RadioGroup) view
		.findViewById(R.id.group_view_language);

	RadioButton vietnam = (RadioButton) view.findViewById(R.id.lan_vi);
	RadioButton english = (RadioButton) view.findViewById(R.id.lan_en);
	if (Language.getLanguage(context) == Language.VI) {
	    vietnam.setChecked(true);
	} else {
	    english.setChecked(true);
	}

	dialog.setTitle(context.getString(R.string.dialog_language_title));
	dialog.setView(view);
	dialog.setNegativeButton("Cancel", new OnClickListener() {

	    @Override
	    public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		dialog.dismiss();
	    }
	});

	dialog.setPositiveButton("OK", new OnClickListener() {

	    @Override
	    public void onClick(DialogInterface dialog, int which) {

		switch (group.getCheckedRadioButtonId()) {
		case R.id.lan_vi:
		    Language.setLanguage(context, Language.VI);
		    break;
		case R.id.lan_en:
		    Language.setLanguage(context, Language.EN);
		    break;

		default:
		    Language.setLanguage(context, Language.VI);
		    break;
		}
		Language.reload = true;
		Language.applySettingLanguage(context);

	    }
	});
    }

    public void show() {

	dialog.show();
    }
}
